package com.cbh.amadeus.common.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;

import java.util.HashMap;
import java.util.Map;

/**
 * @author ChenBiHui
 * @date 2025/5/17
 */
@Slf4j
@Getter
@AllArgsConstructor
public enum MessageApproach {

    /**
     * 直接消息
     */
    DIRECT(1),

    /**
     * 延迟消息
     */
    DELAY(2),
    ;

    /**
     * 缓存 时间复杂度O(1)
     */
    private static final Map<Integer, MessageApproach> CACHE = new HashMap<>(18);

    static {
        for (MessageApproach value : values()) {
            CACHE.put(value.type, value);
        }
    }

    private final Integer type;

    public static MessageApproach find(Byte type) {
        return CACHE.get(Byte.toUnsignedInt(type));
    }
}
